package com.sjq.common.service.impl;


import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sjq.common.dao.MainDao;
import com.sjq.common.service.MainService;

@Service("mainService")
public class MainServiceImpl implements MainService {
    Logger logger = Logger.getLogger(MainServiceImpl.class);
    
    @Autowired
    private MainDao mainDao;
    
    @Override
    public List<Map<String, String>> loadSubMenu(String roledm, String pid) throws SQLException {
        List<Map<String,String>> menuList = mainDao.selectSubMenu(roledm,pid);
        return menuList;
    }
    
    @Override
    public List<Map<String, Object>> loadAllSubMenu(String roledm, String pid) throws SQLException {
        List<Map<String,String>> _2MenuList = mainDao.selectSubMenu(roledm,pid);
        List<Map<String,Object>> r = new ArrayList<Map<String, Object>>();
        
        for(Map<String,String> menu:_2MenuList){
            Map m = (Map)menu;
            List<Map<String,String>> _3MenuList = mainDao.selectSubMenu(roledm,menu.get("cd_id"));
            m.put("children",_3MenuList);
            
            r.add(m);
        }
        return r;
    }
    
}
